/**
 * @author: knowno
 * @create: 2024-09-13 10:40
 * @Version 1.0
 **/
public class JoinThread extends Thread {

    public static void main(String[] args) {

        JoinThread jt = new JoinThread();

        //启动
        jt.start();

        //主线程 =>main方法=>main
        for (int i = 1; i <= 20; i++) {


            try {
                if (i==15)
                {
                    //这里表示jt线程加入主线程，而且主线程主动让出资源，理解为 “插队”.
                    jt.join();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(i + " :" + Thread.currentThread().getName());
        }

    }
    @Override
    public void run() {
        for (int i = 1; i <= 20; i++) {

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(i + " :" + Thread.currentThread().getName());
        }
    }
}
